package Sort;

public class sort1 {
    //插入排序 (升序)
    public static void main(String[] args) {
        int[] arr = {10,5,21,6,7,2,9,11,3,1};
        for(int i=0;i<arr.length;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.println();
        insertSort(arr);
        for(int i=0;i<arr.length;i++){
            System.out.print(arr[i]+" ");
        }
    }

    public static void insertSort(int[] arr){
        for (int i=1;i<arr.length;i++){
            int j=i-1;

            int tmp = arr[i];
            while(j>=0){
                if(arr[j]>tmp){
                    arr[j+1]=arr[j];
                    j--;
                }
                else{
                    break;
                }
            }
            arr[j+1]=tmp;

        }
    }
}
